<script>
import API from "./api";
import baseUser from "@/view/main/components/user/user";
export default {
  extends: baseUser,

  methods: {
    handleLogout() {
      this.$store.commit("setUserInfo", "");
      this.$store.commit("setToken", "");
      this.$store.commit("setAccess", "");
      sessionStorage.clear();
      localStorage.clear();
      this.$router.push({
        name: "login"
      });

      /*
      API.logOut().then(res => {
        this.$store.commit("setUserInfo", "");
        this.$store.commit("setToken", "");
        this.$store.commit("setAccess", "");
        sessionStorage.clear();
        localStorage.clear();
        this.$router.push({
          name: "login"
        });
      });
      */
    },

    mounted() {
      let user = this.$store.state.user.userInfo;
      this.userName = user.userName;
      this.jobNum = user.userId;
    },

    handleSubmit() {
      this.$refs.editPWForm.validate(valid => {
        if (valid) {
          if (this.formInline.newpw !== this.formInline.confirmpw) {
            this.$Message.error("密码与确认密码输入不一致！");
            return;
          }

          let prm = {
            userNum: this.jobNum,
            password: this.formInline.oldpw,
            newpassword: this.formInline.newpw,
            newpassword2: this.formInline.confirmpw
          };

          API.editUserPw(prm).then(res => {
            if (res) {
              this.$Message.success("修改成功,稍后将退出,请重新登录！");
              setTimeout(() => {
                this.modal = false;
                this.handleLogout();
              }, 3000);
            }
          });
        }
      });
    }
  }
};
</script>
